package com.xc.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xc.domain.AjaxResult;
import com.xc.domain.pojo.SysUser;
import com.xc.mapper.SysUserMapper;
import com.xc.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户的相关接口")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private SysUserService sysUserService;

    @ApiOperation(value = "用户列表")
    @PreAuthorize("hasAuthority('system:user:list')")
    @GetMapping("/list")
    public Page<SysUser> list(int page, int pageSize){
        Page<SysUser> sysUserPage = sysUserService.userList(page, pageSize);
        return sysUserPage;
    }
    @ApiOperation(value = "用户查询")
    @PreAuthorize("hasAuthority('system:user:list')")
    @GetMapping("/selectList")
    public AjaxResult select(Integer page, Integer pageSize, String userName, String phoneNumber, Integer status,String createTime,String endTime){
       return sysUserService.select(page, pageSize, userName, phoneNumber, status, createTime, endTime);
    }


    @ApiOperation(value = "用户新增")
    @PreAuthorize("hasAuthority('system:user:add')")
    @PostMapping("/add")
    public AjaxResult add(SysUser sysUser){
        return sysUserService.add(sysUser);
    }

    @ApiOperation(value = "用户修改")
    @PreAuthorize("hasAuthority('system:user:edit')")
    @PostMapping("/upd")
    public AjaxResult upd(SysUser sysUser){
        return sysUserService.update(sysUser);
    }
}
